package com.kfm.jdbc.day01;

import java.sql.SQLException;
import java.util.List;

public class HelperTest {

    public static void main(String[] args) throws SQLException {
        String url = "jdbc:mysql://localhost:3306/scott";
        String user = "root";
        String pass = "root";

        DBHelper helper = new DBHelper(url, user, pass);

        String sql = "select * from emp";

//        Emp emp = helper.selectOne(sql, new EmpResultMapper(), 7369);
//        Dept dept = helper.selectOne(sql, new IResultMapper<Dept>() {
//            @Override
//            public Dept mapper(ResultSet set) {
//                Dept dept = new Dept();
//                try {
//                    dept.setDeptno(set.getInt("deptno"));
//                    dept.setDname(set.getString("dname"));
//                    dept.setLoc(set.getString("loc"));
//                } catch (SQLException e) {
//                    e.printStackTrace();
//                }
//                return dept;
//            }
//        }, 10);

//        Dept obj = helper.selectOne(sql, (set) -> {
//            Dept dept = new Dept();
//            try {
//                dept.setDeptno(set.getInt("deptno"));
//                dept.setDname(set.getString("dname"));
//                dept.setLoc(set.getString("loc"));
//            } catch (SQLException e) {
//                e.printStackTrace();
//            }
//            return dept;
//        }, 10);

        List<Emp> list = helper.selectList(sql, new EmpResultMapper());

        for (Emp obj : list){
            System.out.println(obj);
        }


        helper.close();

    }
}
